package com.lanou.controller;

import com.lanou.service.impl.CompanyServiceImpl;
import com.lanou.service.impl.InterFurServiceImpl;
import com.lanou.service.impl.PcaServiceImpl;
import com.lanou.service.impl.WatchdesignImpl;
import com.lanou.utils.AjaxResult;
import com.lanou.utils.MsgResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;

/**
 * @author 王远航
 *         Created by dllo on 18/3/10.
 */
@Controller
public class MainController {
    /**
     * 初始化列表
     */
    @Resource
    private PcaServiceImpl pcaService;
    @Resource
    private WatchdesignImpl watchdesign;
    @Resource
    private CompanyServiceImpl companyService;
    @Resource
    private InterFurServiceImpl inteFurService;


    /**
     * 查找区
     *
     * @param idStr
     * @return
     * @author wangKing
     * @desc 通过市的id 查找市和区  存入list中
     */
    @ResponseBody
    @RequestMapping("/findarea")
    public AjaxResult findarea(@RequestParam("cityId") String idStr) {
        int cityId = Integer.parseInt(idStr);
        return pcaService.getAreaDate(cityId);
    }

    /**
     * 查找区
     *
     * @param idStr
     * @return
     * @author 王远航
     * @desc 通过市的id 查找4条市和区 并且去除最后一个字 存入list中
     */
    @ResponseBody
    @RequestMapping("/findfourarea")
    public AjaxResult findFourArea(@RequestParam("cityId") String idStr) {
        int cityId = Integer.parseInt(idStr);
        return pcaService.getFourAreaDate(cityId);
    }

    /**
     * @param
     * @return
     * @desc 初始化 查出所有的省
     */
    @ResponseBody
    @RequestMapping("/getAllProvince")
    public AjaxResult findAllProvince() {
        return pcaService.getAllProvinceData();
    }

    /**
     * @param proId
     * @return
     * @author 王远航
     * @desc 通过省的id 当前省的市
     */
    @ResponseBody
    @RequestMapping("/getcity")
    public AjaxResult findCity(@RequestParam("proId") String proId) {
        int provinceId = Integer.parseInt(proId);
        return pcaService.getCityData(provinceId);
    }

    /**
     * @return
     * @author 王远航
     * @desc 获取所有主页图片
     */
    @ResponseBody
    @RequestMapping("/getindexwatchdesign")
    public AjaxResult getAllIndexWatchDesign() {
        return watchdesign.getAllWatchDesginImg();
    }

    /**
     * @return
     * @author 王远航
     * @desc 请求数据接口 获得首页轮播图的所有信息及连接地址
     */
    @ResponseBody
    @RequestMapping("/getindexlunboinformation")
    public AjaxResult getAllIndexIndexImg() {
        return watchdesign.getAllIndexLunboImg();
    }

    /**
     * 王远航
     *
     * @return 品牌特卖信息
     */
    @ResponseBody
    @RequestMapping("/brandselling")
    public AjaxResult getBrandSelling() {
        return MsgResult.brandSell();
    }


    /**
     * 王远航
     *
     * @return 获得所有的智能家居图片
     */
    @ResponseBody
    @RequestMapping("/getallintellfur")
    public AjaxResult getAllIntellFur() {
        return inteFurService.getAllInteFur();
    }



    @RequestMapping("/home")
    public String page(){
        return "home";
    }


}
